//摘自网络·
#include <algorithm>
#include <cstdio>
#include <map>
#define ls p << 1, l, mid
#define rs p << 1 | 1, mid + 1, r
using namespace std;
typedef long long ll;

const int N = (int)5e4 + 10;
const int M = (int)2e5 + 10;

namespace IO_ReadWrite {
#define getchar()                                                              \
  (p1 == p2 && (p2 = (p1 = _buf) + fread(_buf, 1, 1 << 21, stdin), p1 == p2)   \
       ? EOF                                                                   \
       : *p1++)
char _buf[1 << 21], *p1 = _buf, *p2 = _buf;
char ch;
bool ff;
template <typename T> inline void read(T &x) {
  x = 0;
  ff = false;
  ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      ff = true;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  if (ff)
    x = ~x + 1;
  return;
}
template <typename T> inline void write(T x) {
  if (x < 0)
    putchar('-'), x = ~x + 1;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
  return;
}
inline void ReadChar(char &c) {
  do {
    c = getchar();
  } while (c < '0' || c > '9');
  return;
}
template <typename T> inline void writeln(T x) {
  write(x);
  putchar('\n');
  return;
}
} // namespace IO_ReadWrite
using namespace IO_ReadWrite;

struct node {
  ll sum;
} sum[M];

struct nope {
  ll l, r, id;
} f[M];

ll num[N] = {0};
ll cnt[M] = {0};
map<ll, ll> vis;

inline bool cmp(nope a, nope b) { return a.r < b.r; }

struct Segment_Tree {
  ll x, y;
  inline void pushdown(ll p) {
    sum[p].sum = sum[p << 1].sum + sum[p << 1 | 1].sum;
  }
  inline void build(ll p, ll l, ll r) {
    if (l == r) {
      sum[p].sum = 0;
      return;
    }
    ll mid = (l + r) >> 1;
    build(ls);
    build(rs);
    pushdown(p);
    return;
  }
  inline ll query(ll p, ll l, ll r) {
    if (l >= x && r <= y)
      return sum[p].sum;
    ll mid = (l + r) >> 1;
    if (mid < x)
      return query(rs);
    else if (mid >= y)
      return query(ls);
    else
      return query(ls) + query(rs);
  }
  inline void updata(ll p, ll l, ll r, ll k, ll nums) {
    if (l == r) {
      sum[p].sum += nums;
      return;
    }
    ll mid = (l + r) >> 1;
    if (mid >= k)
      updata(ls, k, nums);
    else
      updata(rs, k, nums);
    pushdown(p);
    return;
  }
};

ll n = 0, q = 0, p = 0;

int main() {
  Segment_Tree tree;
  read(n);
  for (ll i = 1; i <= n; i++)
    read(num[i]);
  tree.build(1, 1, n);
  read(q);
  for (ll i = 1; i <= q; i++) {
    read(f[i].l);
    read(f[i].r);
    f[i].id = i;
  }
  sort(f + 1, f + q + 1, cmp);
  p = 1;
  vis.clear();
  for (ll i = 1; i <= q; i++) {
    while (p <= f[i].r) {
      if (vis.find(num[p]) != vis.end()) {
        tree.updata(1, 1, n, vis[num[p]], -num[p]);
      }
      vis[num[p]] = p;
      tree.updata(1, 1, n, p, num[p]);
      p++;
    }
    tree.x = f[i].l;
    tree.y = f[i].r;
    cnt[f[i].id] = tree.query(1, 1, n);
  }
  for (ll i = 1; i <= q; i++)
    writeln(cnt[i]);
  return 0;
}